"""
获取豆瓣电影首页代码
"""
import random
import re
import time

import requests

# 正则表达式捕获组
pattern = re.compile(r'<span class="title">(.+?)</span>')
for page in range(1):
    resp = requests.get(
        url=f'https://movie.douban.com/top250?start={page * 25}',
        headers={
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) '
                          'AppleWebKit/537.36 (KHTML, like Gecko) '
                          'Chrome/88.0.4324.192 Safari/537.36'
        }
    )
    print(resp.status_code)
    movie_titles = pattern.findall(resp.text)
    for title in movie_titles:
        print(title)
    time.sleep(random.randint(3, 5))
